<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>
        使用单位-添加安全管理员
    </title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="../../css/main.css" media="all">
    <script type="text/javascript" src="../../lib/loading/okLoading.js"></script>
    <link rel="stylesheet" href="../../css/bootstrap.css">
    <link rel="stylesheet" href="../../lib/layui/css/layui_2.5.7.css">
    <link href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet">
    <style>
        .layui-table-page select {
            height: 22px;
        }
    </style>
</head>

<body>
<div>


    <form class="layui-form x-center">

        <div class="layui-form-pane" style="margin-top: 15px;margin-left:6%">
            <h5 style="text-align: left;"><b>基本信息</b></h5>
            <div class="layui-form-item">

                <!--<label class="layui-form-label">项目名称</label>-->
                <!--<div class="layui-input-inline">-->
                <!--<input  autocomplete="off"  type="text" class="layui-input" name="casename" placeholder="项目名称">-->
                <!--</div>-->
                <label class="layui-form-label"><span class='x-red'>*</span>姓名</label>
                <div class="layui-input-inline">
                    <input  autocomplete="off"  lay-verify="required" type="text" class="layui-input" name="name" placeholder="姓名">
                </div>
                <label class="layui-form-label"><span class='x-red'>*</span>使用单位</label>
                <div class="layui-input-inline">
                    <select lay-verify="required" name="company" lay-filter="company">
                        <option value="">---</option>
                    </select>
                </div>
            </div>


            <div class="layui-form-item">

                <label class="layui-form-label">手机</label>
                <div class="layui-input-inline">
                    <input  autocomplete="off"  type="text" class="layui-input" name="tel" placeholder="手机">
                </div>
                <label class="layui-form-label">负责项目</label>
                <div class="layui-input-inline">
                    <div id="demo1" style=" margin-top: 1px;"></div>
                </div>

            </div>
            <h5 style="text-align: left;"><b>其他信息</b></h5>
            <div class="layui-form-item">
                <label class="layui-form-label">操作证T3</label>
                <div class="layui-input-inline">
                    <input  autocomplete="off"  type="text" class="layui-input" name="t3code" placeholder="操作证T3">
                </div>
                <label class="layui-form-label">到期日期</label>
                <div class="layui-input-inline">
                    <input  autocomplete="off"  type="text" name="t3codevalidity" id="t3codevalidity" placeholder="请选择"
                           autocomplete="off"
                           class="layui-input">
                </div>

            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">操作证A4</label>
                <div class="layui-input-inline">
                    <input  autocomplete="off"  type="text" class="layui-input" name="a4code" placeholder="操作证A4">
                </div>
                <label class="layui-form-label">到期日期</label>
                <div class="layui-input-inline">
                    <input  autocomplete="off"  type="text" name="a4codevalidity" id="a4codevalidity" placeholder="请选择"
                           autocomplete="off"
                           class="layui-input">
                </div>

            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">身份证</label>
                <div class="layui-input-inline">
                    <input  autocomplete="off"  type="text" class="layui-input" name="code" placeholder="身份证">
                </div>
                <label class="layui-form-label">到期日期</label>
                <div class="layui-input-inline">
                    <input  autocomplete="off"  type="text" name="codevalidity" id="codevalidity" placeholder="请选择"
                           autocomplete="off" class="layui-input">
                </div>

            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">备注信息</label>
                <div class="layui-input-block">
                    <textarea name="remark" placeholder="请输入内容"
                              class="layui-textarea"></textarea>
                </div>
            </div>


            <div style="text-align: center" class="layui-form-item">
                <button class="layui-btn" type="button" lay-filter="sub" lay-submit="sub">
                    保存
                </button>
            </div>
        </div>
    </form>


</div>
</body>

<script type="text/javascript" src="../../js/jquery.min.js"></script>
<script type="text/javascript" src="../../js/myAjax.js"></script>
<script type="text/javascript" src="../../js/pub.js"></script>
<script type="text/javascript" src="../../lib/layui/layui2.5.7.js"></script>
<script type="text/javascript" src="../../js/vue.min.js"></script>
<!-- <script src="lib/layui/layui.js" charset="utf-8"></script> -->
<script src="../../js/x-layui.js" charset="utf-8"></script>
<script src="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/3.3.5/js/bootstrap.min.js"></script>
<script src="../../js/xm-select.js" type="text/javascript" charset="utf-8"></script>
<script>
    layui.use(['laydate', 'element', 'laypage', 'layer', 'form'], function () {
        $ = layui.jquery;//jquery
        laydate = layui.laydate;//日期插件
        lement = layui.element;//面包导航
        laypage = layui.laypage;//分页
        layer = layui.layer;//弹出层
        var form = layui.form;
        okLoading.close($);
    });
</script>


<script>

    layui.use(['laydate'],
        function () {
            var laydate = layui.laydate;

            laydate.render({
                elem: '#a4codevalidity'
            });
            laydate.render({
                elem: '#codevalidity'
            });
            laydate.render({
                elem: '#t3codevalidity'
            });


        });
    var demo1 = xmSelect.render({
        el: '#demo1',
        language: 'zn',
        toolbar: {
            show: true,
        },
        autoRow: true,
        data: []
    });

    layui.use(['form', 'layer'],
        function () {
            var form = layui.form;
            var layer = layui.layer;
            form.on('submit(sub)',
                function (data) {

                    var selectArr = demo1.getValue();
                    var ids = '';
                    $.each(selectArr, function (index, item) {
                        ids += item.value + ','
                    });

                    let form = data.field;
                    form.userId = $userId;
                    form.projectIdstring = ids;
                    let request = {
                        url: '/maintenance/securityadmin/add',
                        data: form,
                        method: "post",
                    };
                    sendRequest(request, (data) => {
                        if (data.code === 0) {
                            layer.alert("操作成功", {
                                    icon: 6
                                },
                                function () {
                                    var index = parent.layer.getFrameIndex(window.name);
                                    parent.layer.close(index);
                                    parent.reload();

                                });
                        } else {
                            layer.alert(data.msg, {
                                icon: 5
                            })
                        }
                    });
                    return false;
                });


            form.on('select(company)', function (data) {

                let request = {
                    url: '/maintenance/project/findByCompanyId',
                    method: 'POST',
                    data: {
                        userId: $userId,
                        companyId: data.value
                    }
                }
                sendRequest(request, res => {

                    var datas = [];

                    $.each(res.data, function (index, item) {
                        datas.push({
                            name: item.name,
                            value: item.id,
                            selected: false
                        })
                    });
                    demo1.update({
                        data: datas
                    });
                    // form.render('select');
                })


            });
        });

</script>

<script>
    // new Vue({
    //     el: "#app",
    //     data: {
    //         statistics: {
    //             kaiAmountOfThisMonth: null,
    //             shouAmountOfThisMonth: null,
    //         }
    //     },
    //     created() {
    //         let request = {
    //             url: 'billFlow/findDataStatistical',
    //             data: {
    //                 userId: $userId,
    //             },
    //             method: "POST",
    //         };
    //         sendRequest(request, (res) => {
    //             this.statistics = res.data
    //         });
    //     }
    // });


    setTimeout(() => {
        let form = layui.form;
        let request2 = {
            url: '/maintenance/company/findAll',
            data: {
                userId: $userId,
            },
            method: "get",
        };
        sendRequest(request2, (res) => {
            let d = res.data;
            $.each(d, function (index, item) {
                let opt = $("<option value=" + item.id + ">" + item.name + "</option>");
                $("select[name='company']").append(opt);
            });
            form.render('select');
        });
    }, 300)


</script>


</html>
